<?php
declare (strict_types = 1);

namespace app\controller;

use app\common\model\Ad;
use app\common\model\ArticlePv;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use think\Request;

class Top extends Common
{

    public function __construct()
    {
        parent::__construct();
        $ad = Ad::where('board_id',7)->select();
        View::assign("ad",$ad);
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {


        $cid = input("get.cid");
        $type = input("get.type");

        if($type == "today"){
            $d_time = strtotime("-0 year -0 month -1 day");
        }

        if($cid){
            $where["cate_id"] = $cid;
        }
        $where["status"] =1;
        if(!isset($where)){
            $where = 1;
        }
        if(!isset($where_time)){
            $d_time = strtotime("-0 year -0 month -7 day");
        }

        $list = ArticlePv::with(["art"])
            ->where("create_time > {$d_time}")
            ->group("aid")
            ->limit(50)
            ->field('*,count(aid) AS sum_count')
            ->order("sum_count DESC")
            ->select();
        View::assign("list",$list);
        return  view();
    }

}
